package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.SwitchBoxVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/30.
 */

public class SwitchBoxAdapter extends LemonRcvAdapter<SwitchBoxVo> {

    private RecyclerTClickListener<SwitchBoxVo> mListener;

    public SwitchBoxAdapter(@Nullable List<SwitchBoxVo> data,
                            RecyclerTClickListener<SwitchBoxVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<SwitchBoxVo> {

        private SwitchBoxVo data;
        private int pos;

        @Bind(R.id.tv_switch_box_position)
        TextView tvSwitchBoxPosition;
        @Bind(R.id.tv_device_type)
        TextView tvDeviceType;
        @Bind(R.id.tv_device_id)
        TextView tvDeviceId;
        @Bind(R.id.ll)
        LinearLayout ll;

        @Override
        public int getLayoutResId() {
            return R.layout.switch_box_recyceler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(SwitchBoxVo switchBoxVo, int position) {

            data = switchBoxVo;
            pos = position;

            tvSwitchBoxPosition.setText(CommonUtil.avoidNullString(switchBoxVo.getArea() + " "
                    + switchBoxVo.getLocation()));

            tvDeviceType.setText(CommonUtil.avoidNullString(switchBoxVo.getModel()));
            tvDeviceId.setText(CommonUtil.avoidNullString(switchBoxVo.getBoxNo()));

        }
    }
}
